import {createStore} from "vuex";
import axios from "axios";
const store =createStore({
state() {
    return {
        sellerIofo: {},
        goods:[],
        show:false,
        carList:[],
        price:0,
    };
},
getters:{
    getPrice(state){

    },
},
mutations: {
    setSeller(state, payload) {
      state.sellerIofo = payload.data;
    },
    setGoods(state, payload) {
      state.goods = payload.data;
    },
    showCar(state) {
      state.show = !state.show;
      console.log('1')
    },
    setCarList(state, payload) {
      const hasItem = state.carList.findIndex((item) => {
        return item.name == payload.item.name;
      });

      if (hasItem === -1) {
        state.carList.push(payload.item);
      }
    },
    kong(state){
      state.carList = [];
 }
  },
  actions: {
    async getGoods({ commit }) {
      const {
        data: { data },
      } = await axios.get("/api/goods");
      commit("setGoods", { data });

    },
    async getSeller({ commit }) {
      const {
        data: { data },
      } = await axios.get("/api/seller");

      commit("setSeller", {
        data,
      });
      console.log(data)
    },
  },
});

export default store;

